<template>
    <div id="content">
        <Header />
        <div class="banner" :style="`background-image: url(${$baseUrl+banner_url})`"></div>
        <div class="allgame content_main">
            <div class="g-title">
                <h4>{{ $t('header_nav_all') }}</h4>
            </div>
            <ul class="list">
                <li v-for="item in game_list" :key="item.id" @click="$router.push('/home/gameCenter/'+item.id)">
                    <a class="gift-box">
                        <div class="img">
<!--                            <img class="game_icon" :src="$baseUrl+item.icon" >-->
                          <div class="game_icon" :style="`background-image: url(${$baseUrl+item.icon});`"></div>
                        </div>
                        <div class="info">
                            <h5>{{ item.title }}</h5>
                            <div class="btn" @click.stop="open_game(item.id,item.pixel_code)">{{ $t('play_game') }}</div>
                        </div>
                    </a>
                </li>
            </ul>
        </div>  
        <div class="footer">
            <Footer />
        </div>

        <div v-if="isShowLoginStore.isShowLogin">
            <Login :isShowLogin_fn="isShowLogin_fn"/>
        </div>
    </div>
</template>

<script setup>
import Header from "@/components/Header/index.vue"  //头部
import Footer from "@/components/Footer/index.vue"  //底部
import axios from '@/utils/api'
import { ref,reactive } from "vue";
import { useRouter } from 'vue-router'
import {useGetGameUrl} from '@/hooks/getGameUrl'
import { useUserInfoStore } from '@/store/modules/user_info/index';
import {useIsShowLogin} from "@/store/modules/isShowLogin/index.js"

const isShowLoginStore = useIsShowLogin();
const isShowLogin_fn = ()=>{
    isShowLoginStore.unShowLogin()
}

const user_infoStore = useUserInfoStore();
let user_info = reactive(user_infoStore.userInfo)
const router = useRouter()

const banner_url = ref('')
const getBanner = async () =>{
    const banner = await axios.get('/getGameCoreBannerList')
    banner_url.value = banner.data[0].banner_url
}
getBanner()

const game_list = reactive([])
const getList = async () =>{
    const list = await axios.get('/gameList?limit=99')
    Object.assign(game_list,list.data.data)
    console.log(game_list);
}
getList()

const open_game = async (game_id,pixel_code) => {
    const data = await useGetGameUrl(game_id,user_info.id)
    console.log(data);
    if(data.code == 5002 || data.code == 5003 || data.message == 'Token失效'){
        // router.push('/login')
        return
    }

    // localStorage.setItem('game_url',data.game_url)
    const url = router.resolve({ path: '/playgame',query: { id: game_id,game_name: data.game_name,pixel_code } }).href;
    // console.log(url);
    window.open(url)
    
}

</script>

<style lang="less" scoped>
.game_icon{
  width: 80px;
  height: 80px;
  background-size: cover;
  background-position: center;
  background-repeat: no-repeat;
  margin: initial;
  margin-right: 10px;
  border-radius: 18px;
  display: inline-block;
  overflow: hidden;
  border: 2px solid #ea9105;
  filter: brightness(1.2);
}
.game_icon::before{
  content: '';
  width: 100%;
  height: 100%;
  background-image: url('https://www.yyfuns.com/h5/assets/icon-DexgPCIM.gif');
  position: absolute;
  background-position: center;
  filter: opacity(.25);
}
.banner {
    width: 100%;
    display: block;
    height: 400px;
    background-repeat: no-repeat;
    background-size: cover;
    background-position: bottom;
}
.allgame{
    min-width: 900px;
    
    .g-title {
        padding-top: 20px;
        h4 {
            font-size: 24px;
            line-height: 36px;
            color: #333;
            font-weight: 400;
        }
        h4:before {
            content: '';
            float: left;
            margin-top: 6px;
            margin-right: 16px;
            z-index: 2;
            background: #00ace6;
            width: 4px;
            height: 24px;
        }
        
    }
    li {
        cursor: pointer;
        margin-top: 20px;
        list-style: none;
        a{
            text-decoration: none;
        }
        font-size: 14px;
        width: calc(100% / 6);
        display: inline-block;
        -webkit-box-sizing: border-box;
        box-sizing: border-box;
        margin-bottom: 20px;
        vertical-align: middle;
        .gift-box {
            margin: 0 auto;
            display: block;
            border-radius: 4px;
            -webkit-transition: all .3s;
            transition: all .3s;
            width: 160px;
            -webkit-box-shadow: 0 1px 2px rgba(0, 0, 0, .1);
            box-shadow: 0 1px 2px rgba(0, 0, 0, .1);
            border-radius: 4px;
            border: solid 1px #ededed;
            position: relative;

            .img {
                width: 80px;
                height: 80px;
                position: relative;
                background-repeat: no-repeat;
                background-position: center;
                -webkit-box-sizing: border-box;
                box-sizing: border-box;
                display: block;
                margin: 10px auto 18px;
                img {
                    display: block;
                    width: 100%;
                    height: 100%;
                    position: absolute;
                    left: 50%;
                    top: 50%;
                    -webkit-transform: translate(-50%, -50%);
                    -ms-transform: translate(-50%, -50%);
                    transform: translate(-50%, -50%);
                }
            }

            .info {
                overflow: hidden;
                -webkit-box-sizing: border-box;
                box-sizing: border-box;
                text-align: center;
                .btn {
                    font-size: 14px;
                    border-radius: 15px;
                    border: 1px solid #fff;
                    width: 92px;
                    height: 32px;
                    line-height: 32px;
                    margin-top: 10px;
                    margin-bottom: 10px;
                    color: #fff;
                    display: inline-block;
                    background-color: #00ace6;
                }

                h5 {
                    font-size: 16px;
                    color: #333;
                    font-weight: bold;
                    line-height: 16px;
                    margin-bottom: 10px;
                    overflow: hidden;
                    text-overflow: ellipsis;
                    white-space: nowrap;
                    -webkit-transition: color .2s;
                    transition: color .2s;
                }
            }
        }
    }
    li:hover{
        .info{
            h5{
                color: #fff;
            }
            .btn{
                background-color: white;
                color: #00ace6;
            }
        }
        a{
            background-color: #24ade4;
            border: solid 1px transparent;
            -webkit-box-shadow: 0 6px 12px 0 rgba(36, 173, 228, .4);
            box-shadow: 0 6px 12px 0 rgba(36, 173, 228, .4);
        }
        
    }
    
}
</style>